<?php

namespace app\common\model;

use think\Model;

class Exam extends Base
{
    /**
     * getInfoById
     * @param $id
     * @return Exam|array|mixed|Model|null
     * @throws
     */
    public function getInfoById($id)
    {
        return $this->where(['id' => $id])->find();
    }

    /**
     * getExamDictById
     * @param array $id
     * @return array
     * @throws
     */
    public function getExamDictById(array $id): array
    {
        $list = $this->where([['id', 'in', $id]])->select();
        $list = $list ? $list->toArray() : [];
        return array_dict($list, 'id');
    }

    /**
     * getPageList
     * @param $where
     * @param $orderBy
     * @param $page
     * @param $limit
     * @return array
     * @throws
     */
    public function getPageList($where, $orderBy, $page, $limit): array
    {
        // 查询数据
        $list = $this->page((int)$page, (int)$limit)->order($orderBy)->select();
        $list = $list ? $list->toArray() : [];

        // 查询记录数
        $count = $this->where($where)->page((int)$page, (int)$limit)->count();

        // 填充数据
        return ['count' => $count, 'data' => $list];
    }
}